<?php

if (!defined("PATH_HD"))
    exit('No direct script access allowed');
// .-----------------------------------------------------------------------------------
// |  Software: [HDPHP framework]
// |   Version: 2013.01
// |      Site: http://www.hdphp.com
// |-----------------------------------------------------------------------------------
// |    Author: 向军 <houdunwangxj@gmail.com>
// | Copyright (c) 2012-2013, http://houdunwang.com. All Rights Reserved.
// |-----------------------------------------------------------------------------------
// |   License: http://www.apache.org/licenses/LICENSE-2.0
// '-----------------------------------------------------------------------------------

/**
 * 创建测试应用目录与控制器文件
 * @package     core
 * @author      后盾向军 <houdunwangxj@gmail.com>
 */
$demoDir = array();
if (defined("APP_GROUP")) {
    $demoDir['demo_app_group_dir'] = PATH_APP_GROUP;
    $demoDir['demo_common_libs_dir'] = PATH_COMMON_LIBS;
    $demoDir['demo_common_config_dir'] = PATH_COMMON_CONFIG;
    $demoDir['demo_common_language_dir'] = PATH_COMMON_LANGUAGE;
    $demoDir['demo_common_model_dir'] = PATH_COMMON_MODEL;
}
$demoDir['demo_app_dir'] = PATH_APP;
$demoDir['demo_app_control_dir'] = PATH_CONTROL;
$demoDir['demo_app_model_dir'] = PATH_MODEL;
$demoDir['demo_app_libs_dir'] = PATH_LIBS;
$demoDir['demo_app_config_dir'] = PATH_CONFIG;
$demoDir['demo_app_tpl_dir'] = PATH_APP . '/tpl';
$demoDir['demo_app_language_dir'] = PATH_LANGUAGE;
$demoDir['demo_app_tpl_public_dir'] = PATH_APP . '/tpl/public';
$demoDir['path_temp_app'] = PATH_TEMP_APP;
$demoDir['path_temp_cache'] = PATH_TEMP_CACHE;
if (defined("APP_GROUP") && is_dir(PATH_APP_GROUP) && !is_writable(PATH_APP_GROUP)) {
    error("应用组目录" . PATH_APP_GROUP . "不可写，请修改权限", false);
}
foreach ($demoDir as $v) {
    dir_create($v);
}


$data = <<<str
<?php
// .-----------------------------------------------------------------------------------
// |  Software: [HDPHP framework]
// |   Version: 2013.01
// |      Site: http://www.hdphp.com
// |-----------------------------------------------------------------------------------
// |    Author: 向军 <houdunwangxj@gmail.com>
// | Copyright (c) 2012-2013, http://houdunwang.com. All Rights Reserved.
// |-----------------------------------------------------------------------------------
// |   License: http://www.apache.org/licenses/LICENSE-2.0
// '-----------------------------------------------------------------------------------
class IndexControl extends Control{
    function index(){
        header("Content-type:text/html;charset=utf-8");
        echo "<div style='font:36px/38px 微软雅黑;text-align:center;color:#333;border-bottom:solid 1px #eee;width:660px;height:30px;padding:20px 0px;'>:-) 感谢使用后盾网HDPHP开源框架</div>";
        echo "<div style='font:12px/16px 微软雅黑;color:#666;margin-top:10px;text-align:center;width:660px;'>开启配置文件中的debug参数，便于监控错误异常 | <a href='http://www.houdunwang.com' style='color:#666;' target='_blank'>后盾网 人人做后盾</a></div>";
    }
}
?>
str;
$demo_control_file = $demoDir['demo_app_control_dir'] . '/Index' . C("CONTROL_FIX") . '.php';
is_file($demo_control_file) || file_put_contents($demo_control_file, $data);

$appConfig = $demoDir['demo_app_config_dir'] . '/config.php';
is_file($appConfig) || copy(PATH_HD_CONFIG . '/config.php', $appConfig); //复制错误页面config.html到模版文件夹下
copy(PATH_HD_TPL . '/app_error.html', $demoDir['demo_app_tpl_public_dir'] . '/error.html'); //复制错误页面error.html到模版文件夹下
copy(PATH_HD_TPL . '/app_success.html', $demoDir['demo_app_tpl_public_dir'] . '/success.html'); //复制正确页面success.html到模版文件夹下

$appLanguageDataUtf8 = <<<str
<?php
if(!defined("PATH_HD"))exit('No direct script access allowed');
// .---------------------------------------------------------------------------.
// |  Software: [HDPHP framework]                                              |
// |   Version: 2013.01                                                        |
// |      Site: http://www.hdphp.com                                           |
// | ------------------------------------------------------------------------- |
// |    Author: hdxj <houdunwangxj@gmail.com>                                  |
// | Copyright (c) 2012-2013, http://houdunwang.com. All Rights Reserved.      |
// | ------------------------------------------------------------------------- |
// |   License: http://www.apache.org/licenses/LICENSE-2.0                     |
// '---------------------------------------------------------------------------'
/**
 * 本文件为语言包测试文件，在视图页面中通过{\$hd.language.title}即可调用
 * 可以创建任意多个语言文件
 * 具体使用哪一个语言包可以能过C("language","zh")这种方式设计或者直接修改配置文件
 * 如果存在应用组，且应用组目录common/language中存在与应用language目录同名的语言包
 * 则应用的语言包优先级高于应用组common中的语言包
 */
return array(
    "title"=>"后盾多语言测试",
);
?>
str;
$appLanguage = $demoDir['demo_app_language_dir'] . '/zh.php';
is_file($appLanguage) || file_put_contents($appLanguage, $appLanguageDataUtf8);

if (defined("APP_GROUP") && !is_file($demoDir['demo_common_language_dir'] . '/zh.php')) {
    file_put_contents($demoDir['demo_common_language_dir'] . '/zh.php', $appLanguageDataUtf8);
//应用组配置文件
    $groupConfigData = <<<str
<?php if(!defined("PATH_HD"))exit('No direct script access allowed');
// .---------------------------------------------------------------------------.
// |  Software: [HDPHP framework]                                              |
// |   Version: 2013.01                                                        |
// |      Site: http://www.hdphp.com                                           |
// | ------------------------------------------------------------------------- |
// |    Author: hdxj <houdunwangxj@gmail.com>                                  |
// | Copyright (c) 2012-2013, http://houdunwang.com. All Rights Reserved.      |
// | ------------------------------------------------------------------------- |
// |   License: http://www.apache.org/licenses/LICENSE-2.0                     |
// '---------------------------------------------------------------------------'
return array(

);
?>
str;
    file_put_contents($demoDir['demo_common_config_dir'] . '/config.php', $groupConfigData);
}
?>